package cn.edu.ctbu.labtest.service.impl;

import cn.edu.ctbu.labtest.dao.CourseRepository;
import cn.edu.ctbu.labtest.domain.Course;
import cn.edu.ctbu.labtest.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CourseImplService implements CourseService {
    @Autowired
    private CourseRepository courseRepository;

    /**
     * 只分页的查询
     * @param pageable
     * @return
     */
    public Page<Course> findAll(Pageable pageable){
        return courseRepository.findAll(pageable);
    }

    /**
     * 分页，带过滤的查询
     */
    public Page<Course> findAll(Example<Course> course, Pageable pageable){
        return courseRepository.findAll(course,pageable);
    }

    /**
     * 读取所有的课程数据
     * @return
     */
    public List<Course> findAll(){
        return courseRepository.findAll();
    }

    /**
     * 通过名字查询教师
     */
    public List<Course> findByName(String name){
        Course course=new Course();
        course.setName(name);
        return courseRepository.findByName(name);
    }

    /**
     * 通过模糊查询查询教师
     */
    public Page<Course> findByNameLike(String name,Pageable pageable){
        Course course=new Course();
        course.setName(name);
        return courseRepository.findByNameLike(name,pageable);
    }

    /**
     * 通过id查找
     * @param id
     * @return
     */
    public Course getById(Integer id){
        Course course=courseRepository.findById(id).orElse(null);
        return course;
    }

}
